<?php
// +-------------------------------------------------------------------
// |
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Service\Api\V1;

use Think\Model;

class EntranceList
{
    public $login = true; //是否需要登录才能访问该接口
    public $title = "用户门禁列表ok";
    public $group = '用户';
    public $desc = "";

    public $input = [

    ];

    public $output = [
        'list' => [
            [
                'id' => 'label=id;',
                'house_id' => 'label=房间id;',
                'building_id' => 'label=楼栋id;',
                'entrance_code' => 'label=门锁编号;',
                'building_name' => 'label=楼栋号;',
                'house_name' => 'label=房间号;',
            ]
        ]
    ];

    public function run($param, $uid, $login_info)
    {
       $model = new Model();
        $sql = "SELECT a.id, b.house_id, b.building_id, c.`name` AS building_name, d.`name` AS house_name FROM `k_entrance_user` as a
LEFT JOIN k_entrance as b ON b.id=a.entrance_id
LEFT JOIN k_building AS c ON c.id=b.building_id
LEFT JOIN k_house AS d ON d.id=b.house_id WHERE  a.uid={$uid};";
        $list = $model->query($sql);
        return [
            'list' => $list,
        ];
    }
}
